<?php

/**
 * This is the model class for table "bookings".
 *
 * The followings are the available columns in table 'bookings':
 * @property integer $booking_id
 * @property string $danhxung
 * @property string $name
 * @property string $address
 * @property string $email
 * @property string $city
 * @property string $country
 * @property string $phone
 * @property string $payment
 * @property integer $numof_adults
 * @property integer $numof_childrens
 * @property integer $numof_baby
 * @property integer $depart_airport_code
 * @property integer $arive_airport_code
 * @property string $departing_date
 * @property string $arriving_date
 * @property string $booking_status
 * @property integer $cost2
 * @property integer $cost1
 */
class Bookings extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'bookings';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name,', 'required','message'=>'không được để trống tên'),
                        array('address', 'required','message'=>'không được để trống địa chỉ'),
                        array('email', 'required','message'=>'không được để trống email'),
                        array('phone,', 'required','message'=>'không được để trống số điện thoại'),
			array('phone', 'numerical', 'integerOnly'=>true,'max'=>99999999999,'min'=>900000000,'message'=>'Số điện thoại chỉ được nhập số','tooSmall'=>'Không đúng định dạng số điện thoại','tooBig'=>'Xin nhập đúng số điện thoại'),
			array('email', 'length', 'max'=>100),
                        array('phone', 'length', 'max'=>12,'message'=>'Xin nhập đúng số điện thoại'),
			array('email', 'email'),
			
                 
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{ 
		return array(
			'booking_id' => 'Booking',
			'danhxung' => 'Danhxung',
			'name' => 'Họ tên',
			'address' => 'Địa chỉ',
			'email' => 'Email',
			'city' => 'City',
			'country' => 'Country',
			'phone' => 'Số điện thoại',
			'payment' => 'Payment',
			'numof_adults' => 'Numof Adults',
			'numof_childrens' => 'Numof Childrens',
			'numof_baby' => 'Numof Baby',
			'depart_airport_code' => 'Depart Airport Code',
			'arive_airport_code' => 'Arive Airport Code',
			'departing_date' => 'Departing Date',
			'arriving_date' => 'Arriving Date',
			'booking_status' => 'Booking Status',
			'cost2' => 'Cost2',
			'cost1' => 'Cost1',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('booking_id',$this->booking_id);
		$criteria->compare('danhxung',$this->danhxung,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('city',$this->city,true);
		$criteria->compare('country',$this->country,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('payment',$this->payment,true);
		$criteria->compare('numof_adults',$this->numof_adults);
		$criteria->compare('numof_childrens',$this->numof_childrens);
		$criteria->compare('numof_baby',$this->numof_baby);
		$criteria->compare('depart_airport_code',$this->depart_airport_code);
		$criteria->compare('arive_airport_code',$this->arive_airport_code);
		$criteria->compare('departing_date',$this->departing_date,true);
		$criteria->compare('arriving_date',$this->arriving_date,true);
		$criteria->compare('booking_status',$this->booking_status,true);
		$criteria->compare('cost2',$this->cost2);
		$criteria->compare('cost1',$this->cost1);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Bookings the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
